package com.guli.sms.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.guli.sms.entity.UndoLogEntity;
import com.guli.sms.service.UndoLogService;

import com.guli.common.utils.R;


/**
 * AT transaction mode undo table
 *
 * @author LuoJunHua
 * @email 1007052116@qq.com
 * @date 2020-11-29 10:59:48
 */
@RestController
@RequestMapping("/sms/undolog")
public class UndoLogController {

    @Autowired
    private UndoLogService undoLogService;


    @GetMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取undoLog分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size, @RequestParam Map<String, Object> params) {

        Page<UndoLogEntity> page = undoLogService.queryPage(currentPage, size, params);

        return R.ok().put("page", page);
    }


    @GetMapping("/info/{branchId}")
    @ApiOperation("根据branchId获取UndoLog")
    public R info(@PathVariable("branchId") Long branchId) {

            UndoLogEntity undoLog = undoLogService.getById(branchId);

        return R.ok().put("undoLog", undoLog);
    }

    @PostMapping("/save")
    @ApiOperation("插入UndoLog")
    public R save(@RequestBody UndoLogEntity undoLog) {

            undoLogService.save(undoLog);

        return R.ok();
    }

    @PostMapping("/saveBatch")
    @ApiOperation("批量插入UndoLog")
    @Transactional
    public R saveBatch(@RequestBody List<UndoLogEntity> undoLogList) {
            undoLogService.saveBatch(undoLogList);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据branchId更新UndoLog")
    public R update(@RequestBody UndoLogEntity undoLog) {
            undoLogService.updateById(undoLog);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据branchId批量删除UndoLog")
    public R delete(@RequestBody Long[] branchIds) {
            undoLogService.removeByIds(Arrays.asList(branchIds));

        return R.ok();
    }

}
